﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Joyintech.Model.inpiao365;
using Joyintech.BLL.inpiao365;
using Joyintech.Common;

namespace Joyintech.Web.inpiao365.AjaxCMS
{
    public partial class ajax_NewFilmList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                //cityid,distid,dayflag,sort
                //根据所属城市、区域、日期、排序字段绑定电影列表
                DataBindMovie(DNTRequest.GetQueryString("cityId"), DNTRequest.GetQueryString("distid"), DNTRequest.GetQueryString("dayflag"), DNTRequest.GetQueryString("sort"));
            }
        }

        /// <summary>
        /// 1,-1,0,0
        /// </summary>
        /// <param name="cityId"></param>
        /// <param name="areaId"></param>
        /// <param name="dayFlag"></param>
        /// <param name="sort"></param>
        private void DataBindMovie(string cityId,string areaId,string dayFlag,string sort)
        {
            List<movieOnTheater> list = new List<movieOnTheater>();

            string strSql = string.Empty;

            //今日
            if(dayFlag == "0")
            {
                //指定城市的所有区域
                if (areaId == "-1")
                {
                    strSql = "cityId=" + cityId + " and MovieSeatTime>='" + DateTime.Now + "' and MovieSeatTime<'" + DateTime.Today.AddDays(1) + "'";
                }
                else//指定城市、区域
                {
                    strSql = "cityId=" + cityId + " and areaId=" + areaId + " and MovieSeatTime>='" + DateTime.Now + "' and MovieSeatTime<'" + DateTime.Today.AddDays(1) + "'";
                }
            }
            else if(dayFlag == "1")//明日
            {
                //指定城市的所有区域
                if (areaId == "-1")
                {
                    strSql = "cityId=" + cityId + " and MovieSeatTime>='" + DateTime.Today.AddDays(1) + "'";
                }
                else//指定城市、区域
                {
                    strSql = "cityId=" + cityId + " and areaId=" + areaId + " and MovieSeatTime>='" + DateTime.Today.AddDays(1) + "'";
                }
            }

            //排序
            if (sort != "0")
            {
                strSql += " order by " + sort;
            }

            //电影有重复，等待过滤
            list = new movieOnTheater_BLL().GetModelList(strSql);

            //绑定列表
            if (list != null && list.Count > 0)
            {
                this.rptFileList.DataSource = list;
                this.rptFileList.DataBind();
            }
        }

        /// <summary>
        /// 根据城市Id获取指定日期(今天或明天)、指定影片Id播放该影片的电影院，影院有重复，等待过滤
        /// </summary>
        /// <param name="movieId"></param>
        /// <returns></returns>
        protected string GetMovieCity(string movieId)
        {
            string strResult = string.Empty;

            List<movieOnTheater> list = new List<movieOnTheater>();

            string strSql = "movieId=" + movieId;

            if(DNTRequest.GetQueryString("dayFlag") == "0")
            {
                strSql += " and MovieSeatTime>='" + DateTime.Now + "' and MovieSeatTime<'" + DateTime.Today.AddDays(1) + "'";
            }
            else
            {
                strSql += " and MovieSeatTime>='" + DateTime.Today.AddDays(1) + "'";
            }

            list = new movieOnTheater_BLL().GetModelList(strSql);

            //遍历上映该影片的电影院，拼接html字符串
            if (list != null && list.Count > 0)
            {
                int Index = 0;

                foreach (movieOnTheater model in list)
                {
                    if (Index == 9)
                    {
                        strResult += "</div><div classname=\"cinemaliuother\" id=\"" + model.MovieId + "\" style=\"display: none\">";
                    }

                    strResult += "<a href=\"/wangp/25/" + model.TheaterId + ".html\">" + model.TheaterName + "</a>";

                    Index++;
                }
            }

            return strResult;
        }
    }
}